#include "input_check.h"

InputCheck::InputCheck(QWidget *parent, const QString& name)
    : QCheckBox(parent), WidgetInput(name)
{
}

void InputCheck::setCallback(Callback callback)
{
    if (callback != nullptr)
    {
        connect(this, &InputCheck::checkStateChanged, this, [=](Qt::CheckState state) {
            callback(state == Qt::Checked);
        });
    }
}

void InputCheck::setValue(const QString &value)
{
    this->setCheckState(value == "true" ? Qt::Checked : Qt::Unchecked);
}

QString InputCheck::getValue() const
{
    return this->isChecked() ? "true" : "false";
}

bool InputCheck::isEmpty() const
{
    return false;
}
